package weblib

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"goMicro/day05/client/services"
)

// 中间件
func InitMiddleware(prodService services.ProdService) gin.HandlerFunc {
	return func(ctx *gin.Context) {

		ctx.Keys = make(map[string]interface{})
		ctx.Keys["prodService"] = prodService
		ctx.Next()
	}
}
func ErrorMiddleware() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		defer func() {
			if r := recover(); r != nil {
				ctx.JSON(500, gin.H{"status": fmt.Sprintf("%s", r)})
				fmt.Println("#####  ", r)
				ctx.Abort()
			}
		}()
		ctx.Next()
	}

}
